<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
        echo 'adeadd(master)zdd1over';
        echo 'adeaddzdd1over';
		echo 'bug2';
		$this->display('login');
    }
	public function login(){
		$logintype = $_GET['logintype'];
		//登录状态
		if($logintype == 0 ){
			$User_phone =$_POST['user_phone'];
			$password   =$_POST['password'];
			$info = M('user_basicinfo');
			$res  = $info -> where('User_phone ='.$User_phone)->find();
			var_dump($res);die;
			//账号密码不能为空,这里有更为详细的验证规则,包括手机号正确性判断之后完善
			if($User_phone == ''&&$password == ''){
				$this->error("账户或密码不能为空");
			}
			//账户正确性判断
			if($password != $res['password']){
				$this->error("密码不能为空");
			}
			session('User_phone',$User_phone);
			$this->assign($res);
			$res  = $info -> where('User_phone ='.$_SESSION['User_phone'])->find();
			$this->assign($res);
			$plan = M('planinfo');
			$list = $plan->order('Plan_time desc')->limit(10)->select();
			for($i=0;$i<count($list);$i++){ 
				$list[$i]['endnum']       = count(explode(",",$list[$i]['end']));
				$list[$i]['endnumbefore'] = $list[$i]['endnum']-1;
				$list[$i]['end']          = explode(",",$list[$i]['end']);
				$list[$i]['endplace']     = $list[$i]['end'][$list[$i]['endnum']-1];
				$list[$i]['host_photo']     = explode(",",$list[$i]['host_photo']);
				$list[$i]['host_photo']=empty($list[$i]['host_photo'][0]) ? 'none':$list[$i]['host_photo'];
				$list[$i]['host_photo_num'] = count($list[$i]['host_photo']);
				$list[$i]['plan_time_a']    = date("Y-m-d H:i:s",$list[$i]['plan_time']);
				$list[$i]['plan_time']      = date("Y-m-d",$list[$i]['plan_time']);
			}
			$this->assign('list',$list);
			$this->display('homepage');
		//非登录状态返回个人主页
		}else{
			$info = M('user_basicinfo');
			$res  = $info -> where('User_phone ='.$_SESSION['User_phone'])->find();
			$this->assign($res);
			$this->display('homepage');
		}
	}
}